<?php

$id_classi = array();
foreach($_SESSION['__user__']->getClasses() as $a)
	array_push($id_classi, "'".$a['anno_corso']." ".$a['sezione']."'");
$in = join(",", $id_classi);
$max_events = 3;

$sel_impegni = "SELECT eventi.*, CASE WHEN DATE_ADD(data_evento, INTERVAL '-7' DAY)  > NOW() THEN 'no' ELSE 'yes' END AS red_style FROM eventi WHERE data_evento > NOW() AND (classe IN ($in) OR classe IS NULL) AND has_sons = 0 ORDER BY data_evento ASC LIMIT $max_events";
//print $sel_impegni;
$res_impegni = $db->executeQuery($sel_impegni);
if($res_impegni->num_rows > 0){
?>

<h2>Prossimi impegni:</h2>
<div class="box">
<?php
while($impegno = $res_impegni->fetch_assoc()){
	list($data, $ora) = split(" ", $impegno['data_evento']);
?>
<p>
<strong><?php if($impegno['red_style'] == "yes") print "<span class='important'>" ?><?php print format_date($data, SQL_DATE_STYLE, IT_DATE_STYLE, "/")." ".substr($ora, 0, 5) ?><?php if($impegno['red_style'] == "yes") print "</span>" ?></strong><br />
<?php print $impegno['abstract'] ?>
</p>
<?php
}
?>
</div>
<?php } ?>